package vn.hung.data.graphs;

import vn.hung.exceptions.InvalidEdgeTypeException;

public class Edge {
	public static int EDGE_WEIGHT_INT = 0;
	public static int EDGE_WEIGHT_FLOAT = 1;
	
	private int x;
	private int y;
	private int edgeType = -1;
	private int edgeWeightInt = 0;
	private float edgeWeightFloat = 0.0F;
	
	public Edge() {
		setX(0);
		setY(0);
	}
	
	public Edge(int x, int y) {
		this.setX(x);
		this.setY(y);
	}
	
	public Edge(int x, int y, int weight) {
		this.setX(x);
		this.setY(y);
		this.edgeWeightInt = weight;
	}
	
	public Edge(int x, int y, float weight) {
		this.setX(x);
		this.setY(y);
		this.edgeWeightFloat = weight;
	}
	public void setEdgeType(int type) {
		this.edgeType = type;
	}
	
	public void setEdgeWeight(int weight) throws InvalidEdgeTypeException {
		if (edgeType != EDGE_WEIGHT_INT) {
			throw new InvalidEdgeTypeException("Edge type is invalid! Set edge type as integer!");
		}
		edgeWeightInt = weight;
	}
	
	public void setEdgeWeight(float weight) throws InvalidEdgeTypeException {
		if (edgeType != EDGE_WEIGHT_FLOAT) {
			throw new InvalidEdgeTypeException("Edge type is invalid! Set edge type as float!");
		}
		edgeWeightFloat = weight;
	}
	
	public int getEdgeWeightInt() throws InvalidEdgeTypeException {
		if (edgeType != EDGE_WEIGHT_INT) {
			throw new InvalidEdgeTypeException("Edge type is invalid! Set edge type as integer!");
		}
		return edgeWeightInt;
	}
	public float getEdgeWeightFloat() throws InvalidEdgeTypeException {
		if (edgeType != EDGE_WEIGHT_FLOAT) {
			throw new InvalidEdgeTypeException("Edge type is invalid! Set edge type as float!");
		}
		return edgeWeightFloat;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
	
	public String toString() {
		String str = "";
		str = x + "	" + y;
		if (edgeType == EDGE_WEIGHT_FLOAT) {
			str += "	" + edgeWeightFloat;
		} else if (edgeType == EDGE_WEIGHT_INT) {
			str += "	" + edgeWeightInt;
		} 
		return str;
	}
	
	public String toString(String delimiter) {
		String str = "";
		str = x + delimiter + y;
		if (edgeType == EDGE_WEIGHT_FLOAT) {
			str += delimiter + edgeWeightFloat;
		} else if (edgeType == EDGE_WEIGHT_INT) {
			str += delimiter+ edgeWeightInt;
		} 
		return str;
	}

}
